package xiaohu.day10.HJ103;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i]=scanner.nextInt();
            }

            int[][] dp = new int[n + 1][n + 1];
            for (int i = 0; i <n; i++) {
                for (int j = i+1; j <n ; j++) {
                    int max=0;
                    for (int k = i; k <=j ; k++) {
                        if (arr[j] > arr[k]) {
                            int temp=dp[i][k]+1;
                            if (temp>max){
                                max=temp;
                            }
                        }
                    }
                    dp[i][j]=max;
                }
            }

            int allMax=0;
            for (int i = 0; i <=n; i++) {
                for (int j = i+1; j <=n ; j++) {
                    if (dp[i][j] > allMax) {
                        allMax=dp[i][j];
                    }
                }
            }
            System.out.println(allMax+1);
        }
    }
}
